﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;
using System.Text;
using System.Data;
public partial class uc_detailproduct : System.Web.UI.UserControl
{
    public static string pid = string.Empty;
    public static string cid = string.Empty;
    public void BuildBuyHtml()
    {
        ltBuy.Text = "<a href=\"javascript:void(0);\" onclick=\"javascript:ClientBuyProduct('" + DAL.EnvInfo.HttpRoot + "','" + pid + "');\"><img id=\"imgBuy\" src=\"" + DAL.EnvInfo.HttpRoot + "images/icons/datmua.gif\" /></a>";
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        pid = HttpContext.Current.Request.QueryString["pid"];
        if (pid == null || pid == "")
            pid = "0";
        cid = HttpContext.Current.Request.QueryString["cid"];
        if (cid == null || cid == "")
            cid = "0";
        if (!IsPostBack)
        {
            BuildBuyHtml();
            StringBuilder imagesText = new StringBuilder();
            StringBuilder productDetail = new StringBuilder();

            DataTable dt = new CmsBLL().ReadingProductsById(pid);
            if (dt.Rows.Count == 0)
                return;

            //if (dt.Rows[0]["ProductID"] != null)
            //    lblproductCode.Text = (string)dt.Rows[0]["ProductID"];

            if (dt.Rows[0]["ProductName"] != null)
                lbltitle.Text = (string)dt.Rows[0]["ProductName"];

            if (dt.Rows[0]["Description"] != null)
                lbldescription.Text = (string)dt.Rows[0]["Description"];

            if (dt.Rows[0]["KhuyenMai"] != null)
                lblSaleOff.Text = dt.Rows[0]["KhuyenMai"].ToString();

            if (dt.Rows[0]["Status"] != null)
                lblStatus.Text = new CmsBLL().GetProductStatus(dt.Rows[0]["Status"].ToString());

            if (dt.Rows[0]["NewPrice"] != null)
                lblprice.Text = Convert.ToInt64(dt.Rows[0]["NewPrice"]).ToString("#,###");

            if (dt.Rows[0]["OldPrice"] != null)
                lblprice_old.Text = Convert.ToInt64(dt.Rows[0]["OldPrice"]).ToString("#,###");

            

            string Body = string.Empty;
            if (dt.Rows[0]["Body"] != null)
                Body = (string)dt.Rows[0]["Body"];

            string productImage = string.Empty;
            if (dt.Rows[0]["Image"] != null)
                productImage = DAL.EnvInfo.HttpRoot + "smallimages/" + (string)dt.Rows[0]["Image"];

            imagesText.Append(
                "				<a class=\"mainphoto\" rel=\"lightbox-journey\" href=\"" + productImage + "\"><img src=\"" + productImage + "\" /></a>\n" +
                "				<div class=\"thumbs\">\n");
            if (dt.Rows[0]["OtherImage"] != null)
            {
                string[] arrImg = dt.Rows[0]["OtherImage"].ToString().Split((";").ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                for (int i = 0; i < arrImg.Length; i++)
                {
                    imagesText.Append("<a rel=\"lightbox-journey\" href=\"" + DAL.EnvInfo.HttpRoot + "smallimages/" + arrImg[i] + "\" ><img src=\"" + DAL.EnvInfo.HttpRoot + "smallimages/" + arrImg[i] + "\" /></a>\n");
                }
            }
            imagesText.Append(
                    "					<br class=\"clrfix\" />\n" +
                    "				</div>\n"
                );
            litImages.Text = imagesText.ToString();
            ltProductInfo.Text = new CmsBLL().RenderMoreProductDetail(pid, cid, "", 10, 10, 0, "ClientJumpPages", CommonBLL.SiteID);

            //string url = HttpContext.Current.Request.Url.AbsoluteUri;
            //http://localhost:1302/TESTERS/Default6.aspx

            string fbHtml = "<div id=\"fblikediv\">\n" +
                             "           <img src=\"" + DAL.EnvInfo.HttpRoot + "images/fb-like-button.png\" id=\"fblikeimg\" onmouseover=\"return renderFbLike();\">\n" +
                             "       </div>\n" +
                             "<script type=\"text/javascript\">\n" +
                             "           function renderFbLike() {\n" +
                             "               var parent = document.getElementById('fblikediv');\n" +
                             "               var child = document.getElementById('fblikeimg');\n" +
                             "               parent.removeChild(child);\n" +                             
                             //"               var Url = \"http://www.facebook.com/plugins/like.php?href=https%3A%2F%2Fdevelopers.facebook.com%2Fdocs%2Fplugins%2F&width&layout=standard&action=like&show_faces=true&share=true&height=80&appId=431526466950137\";\n" +
                             //"               \n" +
                             //"               var html2 = '<iframe src=\"//www.facebook.com/plugins/like.php?href=http%3A%2F%2Flocalhost%3A49720%2FProjectShoppingCart%2F1%2Fc74_p5555%2Fbanh-rang-bua.html&amp;width&amp;layout=standard&amp;action=like&amp;show_faces=true&amp;share=true&amp;height=80&amp;appId=431526466950137\" scrolling=\"no\" frameborder=\"0\" style=\"border:none; overflow:hidden; height:80px;\" allowTransparency=\"true\"></iframe>';\n" +
                             "               var html2 = '<iframe src=\"//www.facebook.com/plugins/like.php?href=http%3A%2F%2Fcdspna.edu.vn%2Fcdspna%2Fvie%2Fbchdanguy-bgh-daidien-nd-da2f91d0.aspx&amp;width&amp;layout=standard&amp;action=like&amp;show_faces=true&amp;share=true&amp;height=80&amp;appId=431526466950137\" scrolling=\"no\" frameborder=\"0\" style=\"border:none; overflow:hidden; height:80px;\" allowTransparency=\"true\"></iframe>';\n" +                                                          
                             "               document.getElementById('fblikediv').innerHTML = html2;\n" +
                             "           }\n" +
                            "</script>\n";


            ltProductInfo.Text += fbHtml;

            //int CountView = dt.Rows[0]["CountView"]!=null?int.Parse(dt.Rows[0]["CountView"].ToString()):0;
            new CmsBLL().UpdateCountView(pid);

        }
    }
}